<?php
	
	namespace Aspic\Form\Decorator\Form;
	
	use Aspic as A;
	use Aspic\Form;
	
	class Basic extends Form\Decorator\AbstractDecorator implements Form\Decorator\DecoratorInterface {
		
		protected function isRenderable(Form\Element\AbstractElement $el) {
			return ($el instanceof Form\Form);
		}
		
		public function out($form) {
			$this->checkRenderable($form);
			
			$elements = $form->getElements();
			
			$out = $form->outContainerStart();
			
			if(count($elements)) {
				foreach($elements as $element) {
					if($element->isShownedAsLine())
						$out .= $form->opt('elementsLineStart');
					
					$out .= $element->out();
					
					if($element->isShownedAsLine()) {
						$out .= $form->opt('elementsLineEnd')."\n";
						$out .= $form->opt('elementsLineSeparator')."\n";
					}
				}
				
				if(strlen($this->opt('elementsLineSeparator')) AND $element->isShownedAsLine()) {
					$out = substr($out, 0, strlen($out) - strlen($form->opt('elementsLineSeparator')) - 1); // -1 pour le \n
				}
			}
			
			$out .= $form->outContainerEnd();
			
			return $out;
		}
		
	}